/**
 * @author CT
 * @email 994599447@qq.com
 * @date 2017.8.14
 */

'use strict';

import React, { Component } from 'react'
import { Alert } from 'react-native'
import {
    Container,
    Button,
    Text,
    Header,
    Left,
    Body,
    Content,
    Right,
    Title,
    Icon,
    List,
    ListItem,
    Toast,
} from 'native-base'
import * as I18n from '../config/i18n'
import Ionicons from 'react-native-vector-icons/Ionicons'
import * as Storage from '../common/storage'
import * as config from '../config/appConfig'
import Utils from '../common/utils'
import { remindDatas,atTopRemindData } from '../actions/homeActions'

/**
 * 设置
 */
export default class SettingsPage extends Component {

    constructor(props) {
        super(props);

        this._clearRemindData = this._clearRemindData.bind(this);
    }

    //绘制标题栏
    _renderTitleBar = () => {
        return (
            <Header
                androidStatusBarColor="#00797e"
                style={{backgroundColor:'#00adb4'}}>
                <Left>
                    <Button transparent light onPress={()=>{this.props.navigation. goBack()}}>
                        <Icon name='arrow-back' />
                    </Button>
                </Left>
                <Body>
                    <Title>{I18n.t('settings.title')}</Title>
                </Body>
                <Right />
            </Header>
        );
    }

    //清空所有倒计时
    _clearRemindData = () => {
        Alert.alert(
            I18n.t('alert_title'),
            I18n.t('settings.alert_tips'),
            [
              {text: I18n.t('alert_cancel'), style: 'cancel'},
              {text: I18n.t('alert_confirm'), onPress: () => {
                Storage.clearMapForKey(config.StorageKey.RemindDate);
                Storage.remove(config.StorageKey.AtTopId);
                Utils.showToast(I18n.t('settings.clear_remind_success'),'success');
                //刷新倒计时数据
                this.props.dispatch(remindDatas());
                this.props.dispatch(atTopRemindData());
              }},
            ],
            { cancelable: false }
        );
        
    }

    render() {
        return (
            <Container>
                 {this._renderTitleBar()}
                 <Content>
                    <List>
                        {/*<ListItem>
                            <Text style={{flex:1}}>更换首页背景</Text>
                            <Ionicons name = 'ios-arrow-forward' size = {20} color = '#BFBFBF'/>
                        </ListItem>*/}
                        <ListItem onPress={()=>{this._clearRemindData()}}>
                            <Text style={{flex:1}}>{I18n.t('settings.options_clear_remind')}</Text>
                            <Ionicons name = 'ios-arrow-forward' size = {20} color = '#BFBFBF'/>
                        </ListItem>
                        <ListItem onPress={()=>{Utils.showToast(I18n.t('settings.check_update_new'),'success');}}>
                            <Text style={{flex:1}}>{I18n.t('settings.options_check_update')}</Text>
                            <Ionicons name = 'ios-arrow-forward' size = {20} color = '#BFBFBF'/>
                        </ListItem>
                        <ListItem onPress={()=>{this.props.navigation.navigate('AboutPage');}}>
                            <Text style={{flex:1}}>{I18n.t('settings.options_about')}</Text>
                            <Ionicons name = 'ios-arrow-forward' size = {20} color = '#BFBFBF'/>
                        </ListItem>
                    </List>
                 </Content>
            </Container>
        );
    }

}
